package com.zhangyanqiang.traceId.filter.config;

import com.zhangyanqiang.traceId.filter.WebTraceIdFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.Filter;

/**
 * @author zhangyanqiang
 * @date 2021/10/8
 **/
@Configuration
public class TraceIdWebMvcConfiguration implements WebMvcConfigurer {

    /**
     * 过滤器注册traceIdBean
     * @return
     */
    @Bean
    public FilterRegistrationBean registrationTraceIdBean(){
        FilterRegistrationBean<Filter> filterRegisterBean = new FilterRegistrationBean<>();
        filterRegisterBean.setFilter(new WebTraceIdFilter());
        filterRegisterBean.addUrlPatterns("/*");
        filterRegisterBean.setName("webTraceIdFilter");
        return filterRegisterBean;
    }
}
